package com.example.collections;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.NumberUtil;
import org.junit.Test;

import java.math.BigDecimal;
import java.time.Period;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @author csp 2020-12-18
 */
public class StreamTest {

    List<String> list;

    public List<String> list(){
        List<String> list = new ArrayList<>();
        for (int i = 0; i <5 ; i++) {
            list.add(UUID.randomUUID().toString());
        }
        return list;
    }
    @Test
    public void test(){
        List<String> list1 = list();
        List<String> list2 = list();
        List<String> list3 = list();
        List<List<String>> test = Arrays.asList(list1, list2, list3);
        
        for (int i = 1; i < test.size(); i++) {

        }
//        System.out.println(stream.collect(Collectors.toList()));
    }

    public void branchStream(List<String> stringList){
        List<String> newList = list.stream()
                .flatMap(str -> stringList.stream().map(str2 -> str + str2))
                .collect(Collectors.toList());
        this.list = newList;
        System.out.println(newList);
    }
    public List<Integer> integerList(){
        List<Integer> integerList = new ArrayList<>(1000);
        for (int i = 0; i < 1000; i++) {
            integerList.add(i);
        }
        return integerList;
    }
    @Test
    public void test1(){
        List<Integer> integerList = integerList();
//        List<Integer> collect = integerList.parallelStream().map(integer -> integer * integer).collect(Collectors.toList());
//        System.out.println(collect);
        List<Integer> integers = integerList.parallelStream().filter(i -> i % 2 == 0).collect(Collectors.toList());
        System.out.println(integers);
    }
    @Test
    public void test2(){
        List<Integer> integerList = integerList();
        Integer i1 = 123123;
        int i = i1.compareTo(123);
        System.out.println(i);
        integerList.sort(Comparator.naturalOrder());
        System.out.println(integerList);
    }
    @Test
    public void test3(){
        ArrayList<BigDecimal> bigDecimals = ListUtil.toList(BigDecimal.ONE, BigDecimal.valueOf(2), BigDecimal.valueOf(1.5), null);
        List<BigDecimal> collect = bigDecimals.stream().limit(5).collect(Collectors.toList());
        System.out.println(collect);
    }

}
